




let bloodeffictindex:number=0;
let bloddeffictimg=new Image();
bloddeffictimg.src=require('./images/bloodeffic1.png');
export const drawfirebloodeffic=(ptctx:any,mouse_x:number,mouse_y:number,obj_x:number,obj_y:number,obj_width:number,obj_height:number)=>
{
        if (mouse_x+ 10 >= obj_x && mouse_x + 10 <= obj_x + obj_width+10) {
                if (mouse_y + 10 > obj_y && mouse_y + 10 <= obj_y + obj_height+20) {
                        //血溅效果
                        if(bloodeffictindex==0)
                        {
                                bloddeffictimg.src=require('./images/bloodeffic1.png')
                        }
                        else if(bloodeffictindex==1)
                        {
                                bloddeffictimg.src=require('./images/bloodeffic2.png')
                        }
                        else
                        {
                                bloodeffictindex=0;
                                bloddeffictimg.src=require('./images/bloodeffic3.png')
                        }
                        bloodeffictindex=bloodeffictindex+1;
                        ptctx.drawImage(bloddeffictimg,0,0,bloddeffictimg.width,bloddeffictimg.height,mouse_x-20,mouse_y-20,25,25);
               }
       }
}

export const getrandomaction=():string=> {

        // 0-100
        let tempnum: number = Math.floor(Math.random() * (89 - 0 + 1)) + 0;

        if (tempnum >= 15 && tempnum <= 35) {
                return "d";
        } else if (tempnum >= 36 && tempnum <= 56) {
                return "u";
        }
        // else if (tempnum >= 50 && tempnum <= 55) {
        //         return "l";
        // }
        // else if (tempnum >= 60 && tempnum <= 65)
        // {
        //         return "r"
        // }
        else  if (tempnum >= 80 && tempnum <= 82)
        {
                return "fire";
        }
        else
        {
             return   "d";
        }
}

export const getXY=(canvas:any, evt:any)=>{
        let style = window.getComputedStyle(canvas, null);
        //宽高
        let cssWidth = parseFloat(style["width"]);
        let cssHeight = parseFloat(style["height"]);
        //各个方向的边框长度
        // @ts-ignore
        let borderLeft = parseFloat(style["border-left-width"]);
        // @ts-ignore
        let borderTop = parseFloat(style["border-top-width"]);
        // @ts-ignore
        let paddingLeft = parseFloat(style["padding-left"]);
        // @ts-ignore
        let paddingTop = parseFloat(style["padding-top"]);

        let scaleX = canvas.width / cssWidth; // 水平方向的缩放因子
        let scaleY = canvas.height / cssHeight; // 垂直方向的缩放因子

        let x = evt.clientX;
        let y = evt.clientY;

        let rect = canvas.getBoundingClientRect();
        x -= (rect.left + borderLeft + paddingLeft); // 去除 borderLeft paddingLeft 后的坐标
        y -= (rect.top + borderTop + paddingTop); // 去除 borderLeft paddingLeft 后的坐标
        x *= scaleX; // 修正水平方向的坐标
        y *= scaleY; // 修正垂直方向的坐标
        return {x,y}

}


